package order.service.controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import order.service.model.OrderInfo;
import order.service.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import product.api.ProductApi;
import product.model.ProductInfo;

@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @Autowired
    ProductApi productApi;
    @RequestMapping("/{orderId}")
    public OrderInfo getOrderInfoById(@PathVariable("orderId") Integer orderId) {
        return orderService.getOrderInfoById(orderId);
    }
    @RequestMapping("/o1")
    public String o1(@RequestParam("id") Integer id, String userName, HttpServletResponse response) {
        log.info("AddRequestParameter添加的userName: {}",userName);
        response.setStatus(502);
        return productApi.p1(id);
    }
    @RequestMapping("/o2")
    public String o2(@RequestParam("id")Integer id,@RequestParam("name") String name) {
        return productApi.p2(id,name);
    }
    @RequestMapping("/o3")
    public String o3() {
        ProductInfo productInfo = new ProductInfo();
        productInfo.setId(55);
        productInfo.setProductName("张三");
        return productApi.p3(productInfo);
    }
    @RequestMapping("/o4")
    public String o4() {
        ProductInfo productInfo = new ProductInfo();
        productInfo.setId(66);
        productInfo.setProductName("李四66");
        return productApi.p4(productInfo);
    }
}
